/**
 * 
 */
package com.p2p.base.model;

import java.io.File;
import java.util.HashMap;
import java.util.Map;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

import org.springframework.web.servlet.view.freemarker.FreeMarkerConfig;

import com.p2p.base.service.EmailService;

import freemarker.template.Template;

/**
 * @author ruiqi
 *
 */
public abstract class MailTemplate {
	
	private static Map<String,MailTemplate> mailTemplateMap = new HashMap<String,MailTemplate>();
	
	public static void addTemplate(String tempName,MailTemplate mailTemplate){
		mailTemplateMap.put(tempName, mailTemplate);
	}
	
	public static MailTemplate getTemplate(String tempName){
		return mailTemplateMap.get(tempName);
	}

	@PostConstruct
	protected void init(){
		doInitTemplate();
		addTemplate(getTemplateName(),this);
	}
	
	@Resource
	protected FreeMarkerConfig freemarkerConfig;
	
	@Resource
	protected EmailService emailService;
	
	protected abstract String getTemplateName();
	
	protected abstract void doInitTemplate();
	
	private String from;
	
	/**
	 * 标题
	 */
	private String subject;
	
	
	/**
	 * ftl邮件模板
	 */
	private Template ftlTemplate;
	
	
	/**
	 * 图片资源
	 */
	private Map<String,File> imgs = new HashMap<String,File>();
	
	/**
	 * 附件
	 */
	private Map<String,File> attachments = new HashMap<String,File>();
	
	/**
	 * 是否html格式
	 */
	private boolean isHtml = true;

	public String getSubject() {
		return subject;
	}

	public void setSubject(String subject) {
		this.subject = subject;
	}

	public Template getFtlTemplate() {
		return ftlTemplate;
	}

	public void setFtlTemplate(Template ftlTemplate) {
		this.ftlTemplate = ftlTemplate;
	}

	public Map<String, File> getImgs() {
		return imgs;
	}

	public void setImgs(Map<String, File> imgs) {
		this.imgs = imgs;
	}

	public Map<String, File> getAttachments() {
		return attachments;
	}

	public void setAttachments(Map<String, File> attachments) {
		this.attachments = attachments;
	}

	public boolean isHtml() {
		return isHtml;
	}

	public void setHtml(boolean isHtml) {
		this.isHtml = isHtml;
	}

	public String getFrom() {
		return from;
	}

	public void setFrom(String from) {
		this.from = from;
	}

}
